package com.cimu.redis.pubsub;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.io.Serializable;

@Service
public class RedisPublisher {

    @Autowired
    private RedisTemplate<Serializable, Serializable> rt;

    //向通道发送消息的方法
    public void sendChannelMsg(String channel, Object msg) {
        rt.convertAndSend(channel, msg);
    }

    public void sendChannelMsg(Object msg) {
        sendChannelMsg(getChannel(), msg);
    }

    public String getChannel() {
        return "test";
    }

}